// vuex状态管理
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:'tokenxxxx',
    roles:['amdin'], //admin登录['admin'],user登录['user'] //用户角色信息
    userInfo:JSON.parse(sessionStorage.getItem('userInfo')) || {}, //用户个人信息
    menuList:JSON.parse(sessionStorage.getItem('menuList')) || {}, //菜单栏菜单数据
  },
  getters: {
    
  },
  mutations: {
    SET_TOKEN:(state,token)=>{
      state.token = token;
      sessionStorage.setItem('token',JSON.stringify(token));
    },
    SET_USER_INFO:(state,userInfo)=>{
      state.userInfo = userInfo;
      sessionStorage.setItem('userInfo',JSON.stringify(userInfo));
    },
    SET_MENU_LIST:(state,menuList)=>{
      state.menuList = menuList;
      sessionStorage.setItem('menuList',JSON.stringify(menuList));
    },
  },
  actions: {
    setToken:({commit},data)=>{
      commit('SET_TOKEN',data);
    },
    setUserInfo:({commit},data)=>{
      commit('SET_USER_INFO',data);
    },
    setMenuList:({commit},data)=>{
      commit('SET_MENU_LIST',data);
    },
  },
  modules: {
  }
})
